package ACWing.WeeklyRace;
//全球变暖（有案例过不了）
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/12/31 13:41
 */
public class GlobalWarming {
    static int n;
    static char[][]arr=new char[1010][1010];

    static boolean[][]st=new boolean[1010][1010];
    static boolean[][]st2=new boolean[1010][1010];
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        n=sc.nextInt();
        char[][]arr2=new char[n+10][n+10];
        sc.nextLine();
        for (int i = 0; i < n; i++) {
            String s=sc.nextLine();
            arr[i] = s.toCharArray();
            arr2[i]=s.toCharArray();
        }
        int nums=0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(arr2[i][j]=='#'){
                    nums++;
                    dfs2(i,j,arr2);

                }
            }
        }
        // System.out.println(nums);

        dfs(0,0);
        for (int i = 0; i < n; i++) {
            System.out.println(Arrays.toString(arr[i]));
        }
        int num=0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(arr[i][j]=='#'){
                    dfs2(i,j,arr);
                    num++;
                }
            }
        }
//        System.out.println(num);

        System.out.println(nums-num);
    }
    public static void dfs(int x,int y){
        st[x][y]=true;
        if(arr[x][y]=='*'){
            return;
        }

        int[]dx={-1,1,0,0};
        int[]dy={0,0,1,-1};
        for (int i = 0; i < 4; i++) {
            int a=x+dx[i],b=dy[i]+y;
            if(a>=0&&b>=0&&a<n&&b<n&&!st[a][b]){
                if(arr[a][b]=='#'){
                    arr[a][b]='*';
                    continue;
                }
                dfs(a,b);
            }
        }
    }
    public static void dfs2(int x,int y,char[][]arr2){
        if(arr2[x][y]=='.'){
            return ;
        }
        int[]dx={-1,1,0,0};
        int[]dy={0,0,1,-1};
        arr2[x][y]='.';
        for (int i = 0; i < 4; i++) {
            int a=x+dx[i],b=y+dy[i];
            if(a>=0&&b>=0&&a<n&&b<n){
                dfs2(a,b,arr2);
            }
        }

    }
}
